// 上一个作品下一个作品js
var $scope = null;
$(function() {
	var appElement = document.querySelector('[ng-controller=main]');
	$scope = angular.element(appElement).scope();
	var portfolioId = locationHref("portfolioId");
	$scope.portfolioId=portfolioId;
	var portfolioName =decodeURI( locationHref("portfolioName"));
	$scope.portfolioName=portfolioName;
	  initialPage($scope);
	$scope.methods.getArtworkById();
});
// 初始化值
function initialPage($scope) {
	
	
}
function makeElementDisappear() {
 $(".last-warning").hide()
 $(".first-warning").hide()
}
 
var mainApp = angular.module("mainApp", []);
mainApp.controller('main', function($scope) {
	$scope.search={};
	$scope.methods = {
		//单个作品
		getArtworkById : function() {
			$.ajax({
			    url:$.shysUrlPrefix+'/website/getArtworkById?id='+$scope.portfolioId,
			    type:'get',
			    dataType:'JSON',
				async:true,  //同步方式发起请求
			    success:function (data) {
					if (data.data != null) {
					   $scope.getArtworkList = data.data;	//
						$scope.id = data.data.portfolioId;	//
						  $scope.title = data.data.title;	//
						   $scope.createTime = data.data.createTime;	//
					   $scope.$apply();
					    document.getElementById("targetElement").innerHTML = data.data.details;
					} else {
					   
					}
					
			    },
			
			})
		},
		// 左边右边
		getLastOrNextArtwork: function(viewType) {
			console.log(viewType)
			var params='';
			params += '&id='+ $scope.portfolioId
			params += '&portfolioId='+ $scope.id
			params += '&viewType='+viewType.toString()
			$.ajax({
			    url:$.shysUrlPrefix+'/website/getLastOrNextArtwork?'+params,
			    type:'get',
			    dataType:'JSON',
				async:true,  //同步方式发起请求
			    success:function (data) {
					if(viewType=="last"&&data.data==null){
						$(".first-warning").show()
						setTimeout(makeElementDisappear, 5000);
						$(".last-warning").hide()
					}else if(viewType=="next"&&data.data==null){
						$(".first-warning").hide()
						$(".last-warning").show()
						setTimeout(makeElementDisappear, 5000);
					}
					else{
						if (data.data != null) {
							$('.news-list').show();
							 $('.widget-kong').hide();
							$scope.getArtworkList = data.data;	//
							 $scope.portfolioId=data.data.id
							 $scope.title = data.data.title;	//
							  $scope.createTime = data.data.createTime;	//
							$scope.$apply();
							 document.getElementById("targetElement").innerHTML = data.data.details;
						} else {
						   $('.news-list').hide();
						    $('.widget-kong').show();
						}
					}
				
					
			    },
			
			})
		},
		
	};
});











